/**
 * @author Helio
 */
var DataStoreUtil = function() {
	
	return {
		
		getBankAccountStore: function() {
			if (SALE.App.loginType === "remote") {
				this.accountStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/bank_account_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'accounts',
						remoteSort: true,
						fields: ['id', 'code','name','bank']
				    })
				});
				
				this.accountStore.load();
				return this.accountStore;
			} else {
				var accountJson = SALE.App.daoFactory.getBankAccountDao().buildBankAccountsJson();
				
				this.accountStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(accountJson),
				    reader: new Ext.data.JsonReader({
						root: 'accounts',
						remoteSort: true,
				        fields: ['id', 'code','name','bank']
				    })
				});
				this.accountStore.load();
				return this.accountStore;
			}		
			
		},
		
		getCategoriesStore: function() {		
			if (SALE.App.loginType === "remote") {
				this.categoriesStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/category_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'categories',
						remoteSort: true,
						fields: ['id','code','name', 'comment']
				    })
				});
				
				this.categoriesStore.load();
				return this.categoriesStore;
			} else {
				var categoriesJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
				this.categoriesStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(categoriesJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'categories',
						remoteSort: true,
				        fields: ['id','code','name', 'comment']
				    })
				});
				
				this.categoriesStore.load();
				return this.categoriesStore;
			}
		},
		
		getClassificationsStore: function() {		
			if (SALE.App.loginType === "remote") {
				this.classificationStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/classification_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'classifications',
						remoteSort: true,
						fields: ['id','code','name', 'comment']
				    })
				});
				
				this.classificationStore.load();
				return this.classificationStore;
			} else {
				var classificationJson = SALE.App.daoFactory.getClassificationsDao().buildClassificationsJson();
				this.classificationStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(classificationJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'classifications',
						remoteSort: true,
				        fields: ['id','code','name', 'comment']
				    })
				});
				
				this.classificationStore.load();
				return this.classificationStore;
			}
		},
		
		getClientsStore: function() {
			if (SALE.App.loginType === "remote") {
				this.clientsStore = new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/client_list.php',
						method: 'GET'
					}),
					reader: new Ext.data.JsonReader({
						root: 'clients',
						remoteSort: true,
						fields: ['code', 'name', 'tel', 'address', 'email']
					})
				});
				
				this.clientsStore.load();
				return this.clientsStore;
			} else {
				var clientsJson = SALE.App.daoFactory.getClientsDao().buildClientsJson();
				
				this.clientsStore = new Ext.data.Store({
					proxy: new Ext.data.MemoryProxy(clientsJson),
					//remoteSort:true,
					reader: new Ext.data.JsonReader({
						root: 'clients',
						remoteSort: true,
						fields: ['code', 'name', 'tel', 'address', 'email']
					})
				});
				
				this.clientsStore.load();
				
				return this.clientsStore;
			}
		},
		
		getDeptsStore: function() {		
			if (SALE.App.loginType === "remote") {
				this.deptStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/department_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'depts',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'comment']
				    })
				});
				
				this.deptStore.load();
				return this.deptStore;
			} else {
				var deptJson = SALE.App.daoFactory.getCompanyDeptDao().buildDeptsJson();
				this.deptStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(deptJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'depts',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'comment']
				    })
				});
				
				this.deptStore.load();
				return this.deptStore;
			}
		},
		
		getLoginAuthzStore: function() {
			if (SALE.App.loginType === "remote") {
				this.userStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/user_authz_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'users',
				        fields: ['id', 'loginid','name', 'role', 'authz']
				    })
				});
				
				this.userStore.load();
				return this.userStore;
			} else {
				var userJson = SALE.App.daoFactory.getPersonnelDao().buildUsersJson();
				
				this.userStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(userJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'users',
						fields: ['id', 'loginid','name', 'role', 'authz']
				    })
				});
				this.userStore.load();
				return this.userStore;
			}			
		},
		
		getLoginRoleStore: function() {
			if(!this.roleStore) { 
				this.roleStore = new Ext.data.ArrayStore({
			        fields: ['role','name','authz'],
			        data : [['Admin', '管理员','*'],['Common', '普通职员','10,11,70']]
	
			    });
			}
			
			return this.roleStore;

		},
		
		getManufacturersStore: function() {
			if (SALE.App.loginType === "remote") {
				this.classificationStore = new Ext.data.Store({
					proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/manufacturer_list.php',
						method: 'GET'
					}),
					reader: new Ext.data.JsonReader({
						root: 'manufacturers',
						remoteSort: true,
						fields: ['code','name', 'abbr', 'tel', 'email', 'linkman', 'address']
					})
				});
				
				this.classificationStore.load();
				return this.classificationStore;
			} else {
				var manufacturersJson = SALE.App.daoFactory.getManufacturerDao().buildManufacturersJson();
				
				this.manufacturersStore = new Ext.data.Store({
					proxy: new Ext.data.MemoryProxy(manufacturersJson),
					//remoteSort:true,
					reader: new Ext.data.JsonReader({
						root: 'manufacturers',
						remoteSort: true,
						fields: ['code', 'name', 'abbr', 'tel', 'email', 'linkman', 'address']
					})
				});
				
				this.manufacturersStore.load();				
				return this.manufacturersStore;
			}
		},
		
		getProductsStore: function() {
			if (SALE.App.loginType === "remote") {
				this.productsStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/product_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
				    	root: 'products',
						remoteSort: true,
				        fields: ['code','name', 'abbr', 'model', 'specs', 'unit', 'price', 'base_price', 'buy_price', 'manufacturer']
				    })
				});
				
				this.productsStore.load();
				return this.productsStore;
				
			} else {				
				var productsJson = SALE.App.daoFactory.getProductsDao().buildProductsJson();
					
				this.productsStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(productsJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'products',
						remoteSort: true,
				        fields: ['code','name', 'abbr', 'model', 'specs', 'unit', 'price', 'base_price', 'buy_price', 'manufacturer']
				    })
				});
					
				this.productsStore.load();
				
				return this.productsStore;
			}
		},
		
		getStorageStore: function() {
			if (SALE.App.loginType === "remote") {
				this.storageStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/storage_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
				    	root: 'storages',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'comment']
				    })
				});
				
				this.storageStore.load();
				return this.storageStore;
			} else {
				var storageJson = SALE.App.daoFactory.getStoragesDao().buildStoragesJson();
				
				this.storageStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(storageJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'storages',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'comment']
				    })
				});
				this.storageStore.load();
				return this.storageStore;
			}		
			
		},
		
		getUserStore: function() {
			if (SALE.App.loginType === "remote") {
				this.userStore = new Ext.data.Store({
				    proxy: new Ext.data.HttpProxy({
						url: SALE.App.configInfo.url + 'manage/user_list.php', 
						method: 'GET'
					}),
				    reader: new Ext.data.JsonReader({
						root: 'users',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'tel', 'comment', 'loginid', 'password']
				    })
				});
				
				this.userStore.load();
				return this.userStore;
			} else {
				var userJson = SALE.App.daoFactory.getPersonnelDao().buildUsersJson();
				
				this.userStore = new Ext.data.Store({
				    proxy: new Ext.data.MemoryProxy(userJson),
				    //remoteSort:true,
				    reader: new Ext.data.JsonReader({
						root: 'users',
						remoteSort: true,
				        fields: ['id', 'code','name', 'abbr', 'tel', 'comment', 'loginid', 'password']
				    })
				});
				this.userStore.load();
				return this.userStore;
			}			
		},
		
		
		
		
		
		
		
		
		
		getClientPagingStore: function() {
			
			var clientsJson = SALE.App.daoFactory.getClientsDao().buildClientsJson();
				
			this.clientsStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(clientsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'clients',
					remoteSort: true,
			        fields: ['code','name', 'tel', 'address', 'email']
			    })
			});
				
			this.clientsStore.load();
			
			return this.clientsStore;
		},
		
		getCategoryPagingStore: function() {
			
			var categoriesJson = SALE.App.daoFactory.getCategoriesDao().buildCategoriesJson();
				
			this.categoriesStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(categoriesJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'categories',
					remoteSort: true,
			        fields: ['code','name', 'comment']
			    })
			});
				
			this.categoriesStore.load();
			
			return this.categoriesStore;
		},
		
		
		
		getProductsPagingStore: function() {			
			var productsJson = SALE.App.daoFactory.getProductsDao().buildProductsJson();
				
			this.productsStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(productsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'products',
					remoteSort: true,
			        fields: ['code','name', 'abbreviation', 'model', 'specs', 'unit', 'manufacturer', 'origin']
			    })
			});
			
			return this.productsStore;
		},
		
		
		
		
		
		
		
		getManufacturerPagingStore: function() {
				
			var manufacturersJson = SALE.App.daoFactory.getManufacturerDao().buildManufacturersJson();
				
			this.manufacturersStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(manufacturersJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'manufacturers',
					remoteSort: true,
			        fields: ['code','name', 'abbreviation', 'tel', 'email', 'linkman', 'address']
			    })
			});
				
			this.manufacturersStore.load();
			
			return this.manufacturersStore;
		},
		
		
		getSaleMonthlyStatusStore: function(daily) {
			
			if(!daily) {
				daily = new Date();
			}
			var productsJson = SALE.App.daoFactory.getSaleBillDao().searchSaleDailyStatus(daily,true);
				
			this.productsStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(productsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'products',
					remoteSort: true,
			        fields: ['code','name', 'number', 'unit', 'price', 'amount']
			    })
			});
			
			return this.productsStore;
		},
		
		getOneMonthDatesStore: function() {
			if (!this.dateStore) {
				var dateJson = SALE.Utils.createRecentlyDateJson();
				this.dateStore = new Ext.data.Store({
					proxy: new Ext.data.MemoryProxy(dateJson),
					reader: new Ext.data.JsonReader({
						root: 'dates',
						fields: ['name', 'value']
					})
				});
				
				this.dateStore.load();
			}
			
			return this.dateStore;
		},
		
		getOneYearMonthesStore: function() {
			if (!this.monthStore) {
				var monthJson = SALE.Utils.createRecentlyMonthJson();
				this.monthStore = new Ext.data.Store({
					proxy: new Ext.data.MemoryProxy(monthJson),
					reader: new Ext.data.JsonReader({
						root: 'monthes',
						fields: ['name', 'value']
					})
				});
				
				this.monthStore.load();
			}
			
			return this.monthStore;
		}		
	}
	
}();
